@model MVCCornucopia.ViewModels.EmployeeVM
@{
    ViewBag.Title = "Edit";
}


<h2>
    Edit</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@*    ------- This is purely for intellisense support in VS 2010  -------------------*@
@if (false)
{
    <script type="text/javascript" src="~/Scripts/jquery-1.7.1-vsdoc.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate-vsdoc.js"></script>
}
@using (Ajax.BeginForm("Edit", "Employee", new AjaxOptions()
{
    UpdateTargetId = "result",
    HttpMethod = "POST",
    OnComplete = "OnComplete",
    LoadingElementId = "resultLoadingDiv"
}))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Employee</legend>
        @Html.HiddenFor(model => model.EmployeeId)
        @Html.Partial("_CreateOrEdit", Model)
    </fieldset>

    <div class="bottomDialog">
    

        <a href="#" id="cancelLink" class="linkButton">Cancel</a>
        <input type="submit" value="Save" class="regular"/>
    </div>
}
<script type="text/javascript">

    $(document).ready(function () {
        $("#cancelLink").click(function () {
            $("#editDialog").dialog('close');
        })
    });

    function OnComplete(d) {
        try {
            var obj;
            if (d.responseText)
                obj = $.parseJSON(d.responseText);
            else
                obj = $.parseJSON(d.get_data());

            if (obj.Error == "NotAuthorized") {
                alert(obj.Error);
                alert(obj.LogOnUrl);
                document.location = obj.LogOnUrl;

            }

        } catch (e) {
            // nothing
        }

        //-- close the dialog
        $("#editDialog").dialog('close');
        //-- refresh the grid (note simple jquery load)
        $('#divGrid').load('@Url.Action("IndexAjax", "Employee")');
    }

</script>
